﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Technullogy.Web.UI.Weather;

public partial class Default : System.Web.UI.Page
{

    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        btnDemo.Click += btnDemo_Click;
        if (!IsPostBack)
            BindControls();
    }

    void btnDemo_Click(object sender, EventArgs e)
    {
        BindProperties();
        OnInit(new EventArgs());
    }

    protected void btnPayPal_Click(object sender, EventArgs e)
    {
        Response.Redirect("https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=2012206");
    }

    private void BindControls()
    {
        cbBarometer.Checked = Weather1.ShowBarometer;
        txtForecastDays.Text = Weather1.ForecastDaysToDisplay.ToString();
        cbDewpoint.Checked = Weather1.ShowDewpoint;
        cbForecast.Checked = Weather1.ShowForecast;
        cbHumidity.Checked = Weather1.ShowHumidity;
        cbLinks.Checked = Weather1.ShowLinks;
        cbPrecipChance.Checked = Weather1.ShowChanceForPrecipitation;
        cbTwcLogo.Checked = Weather1.ShowTwcLogo;
        cbUvIndex.Checked = Weather1.ShowUvIndex;
        cbVisibility.Checked = Weather1.ShowVisibility;
        cbWindChill.Checked = Weather1.ShowWindChill;
        cbWindDir.Checked = Weather1.ShowWindSpeedAndDirection;
        ddlWeatherSkin.SelectedValue = Weather1.EmbeddedSkin.ToString();
        ddlForecastIconSize.SelectedValue = Weather1.ForecastIconSize.ToString();
        ddlTodayIconSize.SelectedValue = Weather1.TodayIconSize.ToString();
    }

    private void BindProperties()
    {
        Weather1.ShowBarometer = cbBarometer.Checked;
        Weather1.ForecastDaysToDisplay = Int32.Parse(txtForecastDays.Text);
        Weather1.ShowDewpoint = cbDewpoint.Checked;
        Weather1.ShowForecast = cbForecast.Checked;
        Weather1.ShowHumidity = cbHumidity.Checked;
        Weather1.ShowLinks = cbLinks.Checked;
        Weather1.ShowChanceForPrecipitation = cbPrecipChance.Checked;
        Weather1.ShowTwcLogo = cbTwcLogo.Checked;
        Weather1.ShowUvIndex = cbUvIndex.Checked;
        Weather1.ShowVisibility = cbVisibility.Checked;
        Weather1.ShowWindChill = cbWindChill.Checked;
        Weather1.ShowWindSpeedAndDirection = cbWindDir.Checked;
        WeatherSkin weatherSkin = (WeatherSkin)Enum.Parse(typeof(WeatherSkin), ddlWeatherSkin.SelectedValue, true);
        Weather1.EmbeddedSkin = weatherSkin;

        ImageSize todayIconSize = (ImageSize)Enum.Parse(typeof(ImageSize), ddlTodayIconSize.SelectedValue, true);
        Weather1.TodayIconSize = todayIconSize;

        ImageSize forecastIconSize = (ImageSize)Enum.Parse(typeof(ImageSize), ddlForecastIconSize.SelectedValue, true);
        Weather1.ForecastIconSize = forecastIconSize;
    }
}